﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Ruleweaver.Rules.CheckMethods
{
	public abstract class LinqCheckMethod : SequenceCheckMethod
	{
		private readonly LinqResolution _resolution;

		protected LinqCheckMethod()
		{}

		protected LinqCheckMethod(LinqResolution resolution)
		{
			_resolution = resolution;
		}

		protected override bool SupportsTargetType(Type targetType)
		{
			return base.SupportsTargetType(targetType) || IsSequenceType(targetType, typeof(IQueryable<>));
		}

		protected override Type GetEffectiveTargetType(Type targetType)
		{
			return _resolution == LinqResolution.Queryable
				? typeof(IQueryable<>).MakeGenericType(GetElementType(targetType))
				: base.GetEffectiveTargetType(targetType);
		}
	}
}